<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>GraphChi: example_apps/matrix_factorization/graphlab_gas/als_vertex_program.hpp Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td style="padding-left: 0.5em;">
   <div id="projectname">GraphChi
   &#160;<span id="projectnumber">0.1</span>
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.1.1 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>File&#160;Members</span></a></li>
    </ul>
  </div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Namespaces</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark">&#160;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(8)"><span class="SelectionMark">&#160;</span>Macros</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="dir_04810b79264f9fec212054117672ab81.html">example_apps</a></li><li class="navelem"><a class="el" href="dir_2011854b2943d041f2052c56d329401e.html">matrix_factorization</a></li><li class="navelem"><a class="el" href="dir_99c2e3c9a7bbf28031c16c5dd63540ce.html">graphlab_gas</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="headertitle">
<div class="title">als_vertex_program.hpp</div>  </div>
</div><!--header-->
<div class="contents">
<a href="als__vertex__program_8hpp.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno">    1</span>&#160;</div>
<div class="line"><a name="l00025"></a><span class="lineno">   25</span>&#160;<span class="preprocessor">#ifndef ALS_VERTEX_PROGRAM_HPP</span></div>
<div class="line"><a name="l00026"></a><span class="lineno">   26</span>&#160;<span class="preprocessor"></span><span class="preprocessor">#define ALS_VERTEX_PROGRAM_HPP</span></div>
<div class="line"><a name="l00027"></a><span class="lineno">   27</span>&#160;<span class="preprocessor"></span></div>
<div class="line"><a name="l00028"></a><span class="lineno">   28</span>&#160;</div>
<div class="line"><a name="l00040"></a><span class="lineno">   40</span>&#160;<span class="preprocessor">#include &lt;Eigen/Dense&gt;</span></div>
<div class="line"><a name="l00041"></a><span class="lineno">   41</span>&#160;</div>
<div class="line"><a name="l00042"></a><span class="lineno">   42</span>&#160;<span class="comment">//#include &lt;graphlab.hpp&gt;</span></div>
<div class="line"><a name="l00043"></a><span class="lineno">   43</span>&#160;</div>
<div class="line"><a name="l00044"></a><span class="lineno">   44</span>&#160;<span class="comment">//#include &quot;eigen_serialization.hpp&quot;</span></div>
<div class="line"><a name="l00045"></a><span class="lineno">   45</span>&#160;</div>
<div class="line"><a name="l00046"></a><span class="lineno">   46</span>&#160;</div>
<div class="line"><a name="l00047"></a><span class="lineno">   47</span>&#160;<span class="keyword">typedef</span> Eigen::VectorXd vec_type;</div>
<div class="line"><a name="l00048"></a><span class="lineno">   48</span>&#160;<span class="keyword">typedef</span> Eigen::MatrixXd mat_type;</div>
<div class="line"><a name="l00049"></a><span class="lineno">   49</span>&#160;</div>
<div class="line"><a name="l00050"></a><span class="lineno">   50</span>&#160;</div>
<div class="line"><a name="l00063"></a><span class="lineno"><a class="code" href="structvertex__data.html">   63</a></span>&#160;<span class="keyword">struct </span><a class="code" href="structvertex__data.html" title="the vertex data type which contains the latent factor.">vertex_data</a> {</div>
<div class="line"><a name="l00068"></a><span class="lineno"><a class="code" href="structvertex__data.html#adeae9fb728f92ce36bdf7daf6c1110ac">   68</a></span>&#160;  <span class="keyword">static</span> <span class="keywordtype">size_t</span> <a class="code" href="structvertex__data.html#adeae9fb728f92ce36bdf7daf6c1110ac" title="A shared &quot;constant&quot; that specifies the number of latent values to use.">NLATENT</a>;</div>
<div class="line"><a name="l00070"></a><span class="lineno"><a class="code" href="structvertex__data.html#a0992af23f5489f13f07bc924d68e6379">   70</a></span>&#160;  uint32_t <a class="code" href="structvertex__data.html#a0992af23f5489f13f07bc924d68e6379" title="The number of times this vertex has been updated.">nupdates</a>;</div>
<div class="line"><a name="l00072"></a><span class="lineno"><a class="code" href="structvertex__data.html#a89b8e42b50a16c7c49a1c76b5b319853">   72</a></span>&#160;  <span class="keywordtype">float</span> <a class="code" href="structvertex__data.html#a89b8e42b50a16c7c49a1c76b5b319853" title="The most recent L1 change in the factor value.">residual</a>; </div>
<div class="line"><a name="l00073"></a><span class="lineno">   73</span>&#160;</div>
<div class="line"><a name="l00074"></a><span class="lineno"><a class="code" href="structvertex__data.html#a652e9543fe205c866ff39a09fda2ff13">   74</a></span>&#160;  vec_type <a class="code" href="structvertex__data.html#a652e9543fe205c866ff39a09fda2ff13" title="how much the latent value has changed">factor</a>;</div>
<div class="line"><a name="l00079"></a><span class="lineno"><a class="code" href="structvertex__data.html#a7f177e8488c52777a14aef50256dd489">   79</a></span>&#160;  <a class="code" href="structvertex__data.html#a7f177e8488c52777a14aef50256dd489" title="Simple default constructor which randomizes the vertex data.">vertex_data</a>() : <a class="code" href="structvertex__data.html#a0992af23f5489f13f07bc924d68e6379" title="The number of times this vertex has been updated.">nupdates</a>(0), <a class="code" href="structvertex__data.html#a89b8e42b50a16c7c49a1c76b5b319853" title="The most recent L1 change in the factor value.">residual</a>(1) { <a class="code" href="structvertex__data.html#a4caa51a3710a504d31089b0865bb626d" title="Randomizes the latent factor.">randomize</a>(); } </div>
<div class="line"><a name="l00081"></a><span class="lineno"><a class="code" href="structvertex__data.html#a4caa51a3710a504d31089b0865bb626d">   81</a></span>&#160;  <span class="keywordtype">void</span> <a class="code" href="structvertex__data.html#a4caa51a3710a504d31089b0865bb626d" title="Randomizes the latent factor.">randomize</a>() { <a class="code" href="structvertex__data.html#a652e9543fe205c866ff39a09fda2ff13" title="how much the latent value has changed">factor</a>.resize(<a class="code" href="structvertex__data.html#adeae9fb728f92ce36bdf7daf6c1110ac" title="A shared &quot;constant&quot; that specifies the number of latent values to use.">NLATENT</a>); <a class="code" href="structvertex__data.html#a652e9543fe205c866ff39a09fda2ff13" title="how much the latent value has changed">factor</a>.setRandom(); }</div>
<div class="line"><a name="l00083"></a><span class="lineno">   83</span>&#160;  <span class="comment">//void save(graphlab::oarchive&amp; arc) const { </span></div>
<div class="line"><a name="l00084"></a><span class="lineno">   84</span>&#160;  <span class="comment">//  arc &lt;&lt; nupdates &lt;&lt; residual &lt;&lt; factor;        </span></div>
<div class="line"><a name="l00085"></a><span class="lineno">   85</span>&#160;  <span class="comment">//}</span></div>
<div class="line"><a name="l00087"></a><span class="lineno">   87</span>&#160;<span class="comment"></span>  <span class="comment">//void load(graphlab::iarchive&amp; arc) { </span></div>
<div class="line"><a name="l00088"></a><span class="lineno">   88</span>&#160;  <span class="comment">//  arc &gt;&gt; nupdates &gt;&gt; residual &gt;&gt; factor;</span></div>
<div class="line"><a name="l00089"></a><span class="lineno">   89</span>&#160;  <span class="comment">//}</span></div>
<div class="line"><a name="l00090"></a><span class="lineno">   90</span>&#160;}; <span class="comment">// end of vertex data</span></div>
<div class="line"><a name="l00091"></a><span class="lineno">   91</span>&#160;</div>
<div class="line"><a name="l00092"></a><span class="lineno">   92</span>&#160;</div>
<div class="line"><a name="l00098"></a><span class="lineno"><a class="code" href="structedge__data.html">   98</a></span>&#160;<span class="keyword">struct </span><a class="code" href="structedge__data.html" title="The edge data stores the entry in the matrix.">edge_data</a> : <span class="keyword">public</span> <a class="code" href="structgraphlab_1_1_i_s___p_o_d___t_y_p_e.html">graphlab::IS_POD_TYPE</a> {</div>
<div class="line"><a name="l00107"></a><span class="lineno"><a class="code" href="structedge__data.html#a058121c45cac9d350dd70939a023b55d">  107</a></span>&#160;  <span class="keyword">enum</span> <a class="code" href="structedge__data.html#a058121c45cac9d350dd70939a023b55d" title="The type of data on the edge;.">data_role_type</a> { TRAIN, VALIDATE, PREDICT  };</div>
<div class="line"><a name="l00108"></a><span class="lineno">  108</span>&#160;</div>
<div class="line"><a name="l00110"></a><span class="lineno"><a class="code" href="structedge__data.html#a1fc50f971f9fdbb4c9c90e33bda1c758">  110</a></span>&#160;  <span class="keywordtype">float</span> <a class="code" href="structedge__data.html#a1fc50f971f9fdbb4c9c90e33bda1c758" title="the observed value for the edge">obs</a>;</div>
<div class="line"><a name="l00111"></a><span class="lineno">  111</span>&#160;</div>
<div class="line"><a name="l00113"></a><span class="lineno"><a class="code" href="structedge__data.html#a3fbba49eb9690a4fdeeda275d6c9cad9">  113</a></span>&#160;  <a class="code" href="structedge__data.html#a058121c45cac9d350dd70939a023b55d" title="The type of data on the edge;.">data_role_type</a> <a class="code" href="structedge__data.html#a3fbba49eb9690a4fdeeda275d6c9cad9" title="The train/validation/test designation of the edge.">role</a>;</div>
<div class="line"><a name="l00114"></a><span class="lineno">  114</span>&#160;</div>
<div class="line"><a name="l00116"></a><span class="lineno"><a class="code" href="structedge__data.html#a98967d7ad71e7ef996e6b9727e97949c">  116</a></span>&#160;  <a class="code" href="structedge__data.html#a98967d7ad71e7ef996e6b9727e97949c" title="basic initialization">edge_data</a>(<span class="keywordtype">float</span> <a class="code" href="structedge__data.html#a1fc50f971f9fdbb4c9c90e33bda1c758" title="the observed value for the edge">obs</a> = 0, <a class="code" href="structedge__data.html#a058121c45cac9d350dd70939a023b55d" title="The type of data on the edge;.">data_role_type</a> <a class="code" href="structedge__data.html#a3fbba49eb9690a4fdeeda275d6c9cad9" title="The train/validation/test designation of the edge.">role</a> = PREDICT) :</div>
<div class="line"><a name="l00117"></a><span class="lineno">  117</span>&#160;    <a class="code" href="structedge__data.html#a1fc50f971f9fdbb4c9c90e33bda1c758" title="the observed value for the edge">obs</a>(<a class="code" href="structedge__data.html#a1fc50f971f9fdbb4c9c90e33bda1c758" title="the observed value for the edge">obs</a>), <a class="code" href="structedge__data.html#a3fbba49eb9690a4fdeeda275d6c9cad9" title="The train/validation/test designation of the edge.">role</a>(<a class="code" href="structedge__data.html#a3fbba49eb9690a4fdeeda275d6c9cad9" title="The train/validation/test designation of the edge.">role</a>) { }</div>
<div class="line"><a name="l00118"></a><span class="lineno">  118</span>&#160;</div>
<div class="line"><a name="l00119"></a><span class="lineno">  119</span>&#160;}; <span class="comment">// end of edge data</span></div>
<div class="line"><a name="l00120"></a><span class="lineno">  120</span>&#160;</div>
<div class="line"><a name="l00121"></a><span class="lineno">  121</span>&#160;</div>
<div class="line"><a name="l00126"></a><span class="lineno"><a class="code" href="als__vertex__program_8hpp.html#ab9cfd2cad1698282b6c7fd7f7e7fd459">  126</a></span>&#160;<span class="keyword">typedef</span> <a class="code" href="structgraphlab_1_1distributed__graph.html">graphlab::distributed_graph&lt;vertex_data, edge_data&gt;</a> <a class="code" href="als__vertex__program_8hpp.html#ab9cfd2cad1698282b6c7fd7f7e7fd459" title="The graph type is defined in terms of the vertex and edge data.">graph_type</a>;</div>
<div class="line"><a name="l00127"></a><span class="lineno">  127</span>&#160;</div>
<div class="line"><a name="l00128"></a><span class="lineno">  128</span>&#160;</div>
<div class="line"><a name="l00133"></a><span class="lineno">  133</span>&#160;<span class="keyword">inline</span> <a class="code" href="structgraphlab_1_1_graph_lab_vertex_wrapper.html">graph_type::vertex_type</a></div>
<div class="line"><a name="l00134"></a><span class="lineno"><a class="code" href="als__vertex__program_8hpp.html#a713562b4f44b2663241a3dd6292f0dab">  134</a></span>&#160;<a class="code" href="als__vertex__program_8hpp.html#a713562b4f44b2663241a3dd6292f0dab" title="Given a vertex and an edge return the other vertex in the edge.">get_other_vertex</a>(<a class="code" href="structgraphlab_1_1_graph_lab_edge_wrapper.html">graph_type::edge_type</a>&amp; <a class="code" href="structedge.html">edge</a>, </div>
<div class="line"><a name="l00135"></a><span class="lineno">  135</span>&#160;                 <span class="keyword">const</span> <a class="code" href="structgraphlab_1_1_graph_lab_vertex_wrapper.html">graph_type::vertex_type</a>&amp; vertex) {</div>
<div class="line"><a name="l00136"></a><span class="lineno">  136</span>&#160;  <span class="keywordflow">return</span> vertex.<a class="code" href="structgraphlab_1_1_graph_lab_vertex_wrapper.html#abcc164070e228a8133c627703c1917f0" title="Returns the vertex ID of the vertex.">id</a>() == edge.<a class="code" href="structgraphlab_1_1_graph_lab_edge_wrapper.html#a1176dc7f68117e758dad6c65dd7c7358" title="Returns the source vertex of the edge. This function returns a vertex_object by value and as a conseq...">source</a>().<a class="code" href="structgraphlab_1_1_graph_lab_vertex_wrapper.html#abcc164070e228a8133c627703c1917f0" title="Returns the vertex ID of the vertex.">id</a>()? edge.<a class="code" href="structgraphlab_1_1_graph_lab_edge_wrapper.html#a6c4d5eaded1d40e10775707ff7189dc7" title="Returns the target vertex of the edge.">target</a>() : edge.<a class="code" href="structgraphlab_1_1_graph_lab_edge_wrapper.html#a1176dc7f68117e758dad6c65dd7c7358" title="Returns the source vertex of the edge. This function returns a vertex_object by value and as a conseq...">source</a>();</div>
<div class="line"><a name="l00137"></a><span class="lineno">  137</span>&#160;}; <span class="comment">// end of get_other_vertex</span></div>
<div class="line"><a name="l00138"></a><span class="lineno">  138</span>&#160;</div>
<div class="line"><a name="l00139"></a><span class="lineno">  139</span>&#160;</div>
<div class="line"><a name="l00143"></a><span class="lineno"><a class="code" href="als__vertex__program_8hpp.html#afb0b8a4655197699932baa2bac0cc465">  143</a></span>&#160;<span class="keywordtype">double</span> <a class="code" href="als__vertex__program_8hpp.html#afb0b8a4655197699932baa2bac0cc465" title="Given an edge compute the error associated with that edge.">extract_l2_error</a>(<span class="keyword">const</span> <a class="code" href="structgraphlab_1_1_graph_lab_edge_wrapper.html">graph_type::edge_type</a> &amp; <a class="code" href="structedge.html">edge</a>) {</div>
<div class="line"><a name="l00144"></a><span class="lineno">  144</span>&#160;  <span class="keyword">const</span> <span class="keywordtype">double</span> pred = </div>
<div class="line"><a name="l00145"></a><span class="lineno">  145</span>&#160;    edge.<a class="code" href="structgraphlab_1_1_graph_lab_edge_wrapper.html#a1176dc7f68117e758dad6c65dd7c7358" title="Returns the source vertex of the edge. This function returns a vertex_object by value and as a conseq...">source</a>().<a class="code" href="structgraphlab_1_1_graph_lab_vertex_wrapper.html#aa15502c3f0ca6fbfe636a25e1e349aa4" title="Returns a constant reference to the data on the vertex.">data</a>().factor.dot(edge.<a class="code" href="structgraphlab_1_1_graph_lab_edge_wrapper.html#a6c4d5eaded1d40e10775707ff7189dc7" title="Returns the target vertex of the edge.">target</a>().<a class="code" href="structgraphlab_1_1_graph_lab_vertex_wrapper.html#aa15502c3f0ca6fbfe636a25e1e349aa4" title="Returns a constant reference to the data on the vertex.">data</a>().factor);</div>
<div class="line"><a name="l00146"></a><span class="lineno">  146</span>&#160;  <span class="keywordflow">return</span> (edge.<a class="code" href="structgraphlab_1_1_graph_lab_edge_wrapper.html#a3bfdff77561dc08db04ea7cc3fc4d2c8" title="Returns a constant reference to the data on the edge.">data</a>().obs - pred) * (edge.<a class="code" href="structgraphlab_1_1_graph_lab_edge_wrapper.html#a3bfdff77561dc08db04ea7cc3fc4d2c8" title="Returns a constant reference to the data on the edge.">data</a>().obs - pred);</div>
<div class="line"><a name="l00147"></a><span class="lineno">  147</span>&#160;} <span class="comment">// end of extract_l2_error</span></div>
<div class="line"><a name="l00148"></a><span class="lineno">  148</span>&#160;</div>
<div class="line"><a name="l00149"></a><span class="lineno">  149</span>&#160;</div>
<div class="line"><a name="l00154"></a><span class="lineno">  154</span>&#160;<span class="comment">// Commented out for graphchi</span></div>
<div class="line"><a name="l00155"></a><span class="lineno">  155</span>&#160;<span class="comment">/*</span></div>
<div class="line"><a name="l00156"></a><span class="lineno">  156</span>&#160;<span class="comment">inline bool graph_loader(graph_type&amp; graph, </span></div>
<div class="line"><a name="l00157"></a><span class="lineno">  157</span>&#160;<span class="comment">                         const std::string&amp; filename,</span></div>
<div class="line"><a name="l00158"></a><span class="lineno">  158</span>&#160;<span class="comment">                         const std::string&amp; line) {</span></div>
<div class="line"><a name="l00159"></a><span class="lineno">  159</span>&#160;<span class="comment">  ASSERT_FALSE(line.empty()); </span></div>
<div class="line"><a name="l00160"></a><span class="lineno">  160</span>&#160;<span class="comment">  // Determine the role of the data</span></div>
<div class="line"><a name="l00161"></a><span class="lineno">  161</span>&#160;<span class="comment">  edge_data::data_role_type role = edge_data::TRAIN;</span></div>
<div class="line"><a name="l00162"></a><span class="lineno">  162</span>&#160;<span class="comment">  if(boost::ends_with(filename,&quot;.validate&quot;)) role = edge_data::VALIDATE;</span></div>
<div class="line"><a name="l00163"></a><span class="lineno">  163</span>&#160;<span class="comment">  else if(boost::ends_with(filename, &quot;.predict&quot;)) role = edge_data::PREDICT;</span></div>
<div class="line"><a name="l00164"></a><span class="lineno">  164</span>&#160;<span class="comment">  // Parse the line</span></div>
<div class="line"><a name="l00165"></a><span class="lineno">  165</span>&#160;<span class="comment">  std::stringstream strm(line);</span></div>
<div class="line"><a name="l00166"></a><span class="lineno">  166</span>&#160;<span class="comment">  graph_type::vertex_id_type source_id(-1), target_id(-1);</span></div>
<div class="line"><a name="l00167"></a><span class="lineno">  167</span>&#160;<span class="comment">  float obs(0);</span></div>
<div class="line"><a name="l00168"></a><span class="lineno">  168</span>&#160;<span class="comment">  strm &gt;&gt; source_id &gt;&gt; target_id;</span></div>
<div class="line"><a name="l00169"></a><span class="lineno">  169</span>&#160;<span class="comment">  if(role == edge_data::TRAIN || role == edge_data::VALIDATE) strm &gt;&gt; obs;</span></div>
<div class="line"><a name="l00170"></a><span class="lineno">  170</span>&#160;<span class="comment">  // Create an edge and add it to the graph</span></div>
<div class="line"><a name="l00171"></a><span class="lineno">  171</span>&#160;<span class="comment">  graph.add_edge(source_id, target_id+1000000, edge_data(obs, role)); </span></div>
<div class="line"><a name="l00172"></a><span class="lineno">  172</span>&#160;<span class="comment">  return true; // successful load</span></div>
<div class="line"><a name="l00173"></a><span class="lineno">  173</span>&#160;<span class="comment">} // end of graph_loader</span></div>
<div class="line"><a name="l00174"></a><span class="lineno">  174</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l00175"></a><span class="lineno">  175</span>&#160;<span class="comment">*/</span></div>
<div class="line"><a name="l00176"></a><span class="lineno">  176</span>&#160;</div>
<div class="line"><a name="l00177"></a><span class="lineno">  177</span>&#160;</div>
<div class="line"><a name="l00195"></a><span class="lineno"><a class="code" href="classgather__type.html">  195</a></span>&#160;<span class="keyword">class </span><a class="code" href="classgather__type.html" title="The graph loader function is a line parser used for distributed graph construction.">gather_type</a> {</div>
<div class="line"><a name="l00196"></a><span class="lineno">  196</span>&#160;<span class="keyword">public</span>:</div>
<div class="line"><a name="l00201"></a><span class="lineno"><a class="code" href="classgather__type.html#a79352d3ca5b6957aa4b21276c20da59f">  201</a></span>&#160;  mat_type <a class="code" href="classgather__type.html#a79352d3ca5b6957aa4b21276c20da59f" title="Stores the current sum of nbr.factor.transpose() * nbr.factor.">XtX</a>;</div>
<div class="line"><a name="l00202"></a><span class="lineno">  202</span>&#160;</div>
<div class="line"><a name="l00206"></a><span class="lineno"><a class="code" href="classgather__type.html#a319a1856f1ad204ad8fd13592ab9a201">  206</a></span>&#160;  vec_type <a class="code" href="classgather__type.html#a319a1856f1ad204ad8fd13592ab9a201" title="Stores the current sum of nbr.factor * edge.obs.">Xy</a>;</div>
<div class="line"><a name="l00207"></a><span class="lineno">  207</span>&#160;</div>
<div class="line"><a name="l00209"></a><span class="lineno"><a class="code" href="classgather__type.html#a0ef41a0943ab5f4348eaff240ba87774">  209</a></span>&#160;  <a class="code" href="classgather__type.html#a0ef41a0943ab5f4348eaff240ba87774" title="basic default constructor">gather_type</a>() { }</div>
<div class="line"><a name="l00210"></a><span class="lineno">  210</span>&#160;</div>
<div class="line"><a name="l00215"></a><span class="lineno"><a class="code" href="classgather__type.html#aac64cb2fd36d4c39fad0816895df907b">  215</a></span>&#160;  <a class="code" href="classgather__type.html#a0ef41a0943ab5f4348eaff240ba87774" title="basic default constructor">gather_type</a>(<span class="keyword">const</span> vec_type&amp; X, <span class="keyword">const</span> <span class="keywordtype">double</span> y) :</div>
<div class="line"><a name="l00216"></a><span class="lineno">  216</span>&#160;    <a class="code" href="classgather__type.html#a79352d3ca5b6957aa4b21276c20da59f" title="Stores the current sum of nbr.factor.transpose() * nbr.factor.">XtX</a>(X.size(), X.size()), <a class="code" href="classgather__type.html#a319a1856f1ad204ad8fd13592ab9a201" title="Stores the current sum of nbr.factor * edge.obs.">Xy</a>(X.size()) {</div>
<div class="line"><a name="l00217"></a><span class="lineno">  217</span>&#160;    <a class="code" href="classgather__type.html#a79352d3ca5b6957aa4b21276c20da59f" title="Stores the current sum of nbr.factor.transpose() * nbr.factor.">XtX</a>.triangularView&lt;Eigen::Upper&gt;() = X * X.transpose();</div>
<div class="line"><a name="l00218"></a><span class="lineno">  218</span>&#160;    <a class="code" href="classgather__type.html#a319a1856f1ad204ad8fd13592ab9a201" title="Stores the current sum of nbr.factor * edge.obs.">Xy</a> = X * y;</div>
<div class="line"><a name="l00219"></a><span class="lineno">  219</span>&#160;  } <span class="comment">// end of constructor for gather type</span></div>
<div class="line"><a name="l00220"></a><span class="lineno">  220</span>&#160;</div>
<div class="line"><a name="l00222"></a><span class="lineno">  222</span>&#160;<span class="comment">//  void save(graphlab::oarchive&amp; arc) const { arc &lt;&lt; XtX &lt;&lt; Xy; }</span></div>
<div class="line"><a name="l00223"></a><span class="lineno">  223</span>&#160;</div>
<div class="line"><a name="l00225"></a><span class="lineno">  225</span>&#160; <span class="comment">// void load(graphlab::iarchive&amp; arc) { arc &gt;&gt; XtX &gt;&gt; Xy; }  </span></div>
<div class="line"><a name="l00226"></a><span class="lineno">  226</span>&#160;</div>
<div class="line"><a name="l00231"></a><span class="lineno"><a class="code" href="classgather__type.html#a672f8aac3ab0b1bb48e857b77307f621">  231</a></span>&#160;  <a class="code" href="classgather__type.html" title="The graph loader function is a line parser used for distributed graph construction.">gather_type</a>&amp; <a class="code" href="classgather__type.html#a672f8aac3ab0b1bb48e857b77307f621" title="Save the values to a binary archive.">operator+=</a>(<span class="keyword">const</span> <a class="code" href="classgather__type.html" title="The graph loader function is a line parser used for distributed graph construction.">gather_type</a>&amp; other) {</div>
<div class="line"><a name="l00232"></a><span class="lineno">  232</span>&#160;    <span class="keywordflow">if</span>(other.<a class="code" href="classgather__type.html#a319a1856f1ad204ad8fd13592ab9a201" title="Stores the current sum of nbr.factor * edge.obs.">Xy</a>.size() == 0) {</div>
<div class="line"><a name="l00233"></a><span class="lineno">  233</span>&#160;      ASSERT_EQ(other.<a class="code" href="classgather__type.html#a79352d3ca5b6957aa4b21276c20da59f" title="Stores the current sum of nbr.factor.transpose() * nbr.factor.">XtX</a>.rows(), 0);</div>
<div class="line"><a name="l00234"></a><span class="lineno">  234</span>&#160;      ASSERT_EQ(other.<a class="code" href="classgather__type.html#a79352d3ca5b6957aa4b21276c20da59f" title="Stores the current sum of nbr.factor.transpose() * nbr.factor.">XtX</a>.cols(), 0);</div>
<div class="line"><a name="l00235"></a><span class="lineno">  235</span>&#160;    } <span class="keywordflow">else</span> {</div>
<div class="line"><a name="l00236"></a><span class="lineno">  236</span>&#160;      <span class="keywordflow">if</span>(<a class="code" href="classgather__type.html#a319a1856f1ad204ad8fd13592ab9a201" title="Stores the current sum of nbr.factor * edge.obs.">Xy</a>.size() == 0) {</div>
<div class="line"><a name="l00237"></a><span class="lineno">  237</span>&#160;        ASSERT_EQ(<a class="code" href="classgather__type.html#a79352d3ca5b6957aa4b21276c20da59f" title="Stores the current sum of nbr.factor.transpose() * nbr.factor.">XtX</a>.rows(), 0); </div>
<div class="line"><a name="l00238"></a><span class="lineno">  238</span>&#160;        ASSERT_EQ(<a class="code" href="classgather__type.html#a79352d3ca5b6957aa4b21276c20da59f" title="Stores the current sum of nbr.factor.transpose() * nbr.factor.">XtX</a>.cols(), 0);</div>
<div class="line"><a name="l00239"></a><span class="lineno">  239</span>&#160;        <a class="code" href="classgather__type.html#a79352d3ca5b6957aa4b21276c20da59f" title="Stores the current sum of nbr.factor.transpose() * nbr.factor.">XtX</a> = other.<a class="code" href="classgather__type.html#a79352d3ca5b6957aa4b21276c20da59f" title="Stores the current sum of nbr.factor.transpose() * nbr.factor.">XtX</a>; <a class="code" href="classgather__type.html#a319a1856f1ad204ad8fd13592ab9a201" title="Stores the current sum of nbr.factor * edge.obs.">Xy</a> = other.<a class="code" href="classgather__type.html#a319a1856f1ad204ad8fd13592ab9a201" title="Stores the current sum of nbr.factor * edge.obs.">Xy</a>;</div>
<div class="line"><a name="l00240"></a><span class="lineno">  240</span>&#160;      } <span class="keywordflow">else</span> {</div>
<div class="line"><a name="l00241"></a><span class="lineno">  241</span>&#160;        <a class="code" href="classgather__type.html#a79352d3ca5b6957aa4b21276c20da59f" title="Stores the current sum of nbr.factor.transpose() * nbr.factor.">XtX</a>.triangularView&lt;Eigen::Upper&gt;() += other.<a class="code" href="classgather__type.html#a79352d3ca5b6957aa4b21276c20da59f" title="Stores the current sum of nbr.factor.transpose() * nbr.factor.">XtX</a>;  </div>
<div class="line"><a name="l00242"></a><span class="lineno">  242</span>&#160;        <a class="code" href="classgather__type.html#a319a1856f1ad204ad8fd13592ab9a201" title="Stores the current sum of nbr.factor * edge.obs.">Xy</a> += other.<a class="code" href="classgather__type.html#a319a1856f1ad204ad8fd13592ab9a201" title="Stores the current sum of nbr.factor * edge.obs.">Xy</a>;</div>
<div class="line"><a name="l00243"></a><span class="lineno">  243</span>&#160;      }</div>
<div class="line"><a name="l00244"></a><span class="lineno">  244</span>&#160;    }</div>
<div class="line"><a name="l00245"></a><span class="lineno">  245</span>&#160;    <span class="keywordflow">return</span> *<span class="keyword">this</span>;</div>
<div class="line"><a name="l00246"></a><span class="lineno">  246</span>&#160;  } <span class="comment">// end of operator+=</span></div>
<div class="line"><a name="l00247"></a><span class="lineno">  247</span>&#160;</div>
<div class="line"><a name="l00248"></a><span class="lineno">  248</span>&#160;}; <span class="comment">// end of gather type</span></div>
<div class="line"><a name="l00249"></a><span class="lineno">  249</span>&#160;</div>
<div class="line"><a name="l00250"></a><span class="lineno">  250</span>&#160;</div>
<div class="line"><a name="l00251"></a><span class="lineno">  251</span>&#160;</div>
<div class="line"><a name="l00255"></a><span class="lineno"><a class="code" href="classals__vertex__program.html">  255</a></span>&#160;<span class="keyword">class </span><a class="code" href="classals__vertex__program.html">als_vertex_program</a> : </div>
<div class="line"><a name="l00256"></a><span class="lineno">  256</span>&#160;  <span class="keyword">public</span> <a class="code" href="structgraphlab_1_1ivertex__program.html">graphlab::ivertex_program</a>&lt;graph_type, gather_type,</div>
<div class="line"><a name="l00257"></a><span class="lineno">  257</span>&#160;                                   graphlab::messages::sum_priority&gt;,</div>
<div class="line"><a name="l00258"></a><span class="lineno">  258</span>&#160;  <span class="keyword">public</span> <a class="code" href="structgraphlab_1_1_i_s___p_o_d___t_y_p_e.html">graphlab::IS_POD_TYPE</a> {</div>
<div class="line"><a name="l00259"></a><span class="lineno">  259</span>&#160;<span class="keyword">public</span>:</div>
<div class="line"><a name="l00261"></a><span class="lineno"><a class="code" href="classals__vertex__program.html#a4d3fe82f9b913c88361646fecea3e181">  261</a></span>&#160;  <span class="keyword">static</span> <span class="keywordtype">double</span> <a class="code" href="classals__vertex__program.html#a4d3fe82f9b913c88361646fecea3e181">TOLERANCE</a>;</div>
<div class="line"><a name="l00262"></a><span class="lineno">  262</span>&#160;  <span class="keyword">static</span> <span class="keywordtype">double</span> LAMBDA;</div>
<div class="line"><a name="l00263"></a><span class="lineno">  263</span>&#160;  <span class="keyword">static</span> <span class="keywordtype">size_t</span> MAX_UPDATES;</div>
<div class="line"><a name="l00264"></a><span class="lineno">  264</span>&#160;</div>
<div class="line"><a name="l00266"></a><span class="lineno"><a class="code" href="classals__vertex__program.html#aa70153f16b28263ed6112d012d7a3e86">  266</a></span>&#160;  edge_dir_type <a class="code" href="classals__vertex__program.html#aa70153f16b28263ed6112d012d7a3e86">gather_edges</a>(<a class="code" href="classgraphlab_1_1icontext.html">icontext_type</a>&amp; context, </div>
<div class="line"><a name="l00267"></a><span class="lineno">  267</span>&#160;                             <span class="keyword">const</span> <a class="code" href="structgraphlab_1_1_graph_lab_vertex_wrapper.html">vertex_type</a>&amp; vertex)<span class="keyword"> const </span>{ </div>
<div class="line"><a name="l00268"></a><span class="lineno">  268</span>&#160;    <span class="keywordflow">return</span> graphlab::ALL_EDGES; </div>
<div class="line"><a name="l00269"></a><span class="lineno">  269</span>&#160;  }; <span class="comment">// end of gather_edges </span></div>
<div class="line"><a name="l00270"></a><span class="lineno">  270</span>&#160;</div>
<div class="line"><a name="l00272"></a><span class="lineno"><a class="code" href="classals__vertex__program.html#ab6263c7cdde54dea2c1cd50b4c732169">  272</a></span>&#160;  gather_type <a class="code" href="classals__vertex__program.html#ab6263c7cdde54dea2c1cd50b4c732169">gather</a>(<a class="code" href="classgraphlab_1_1icontext.html">icontext_type</a>&amp; context, <span class="keyword">const</span> <a class="code" href="structgraphlab_1_1_graph_lab_vertex_wrapper.html">vertex_type</a>&amp; vertex, </div>
<div class="line"><a name="l00273"></a><span class="lineno">  273</span>&#160;                     <a class="code" href="structgraphlab_1_1_graph_lab_edge_wrapper.html">edge_type</a>&amp; <a class="code" href="structedge.html">edge</a>)<span class="keyword"> const </span>{</div>
<div class="line"><a name="l00274"></a><span class="lineno">  274</span>&#160;    <span class="keywordflow">if</span>(edge.<a class="code" href="structgraphlab_1_1_graph_lab_edge_wrapper.html#a3bfdff77561dc08db04ea7cc3fc4d2c8" title="Returns a constant reference to the data on the edge.">data</a>().<a class="code" href="structedge__data.html#a3fbba49eb9690a4fdeeda275d6c9cad9" title="The train/validation/test designation of the edge.">role</a> == edge_data::TRAIN) {</div>
<div class="line"><a name="l00275"></a><span class="lineno">  275</span>&#160;      <span class="keyword">const</span> <a class="code" href="structgraphlab_1_1_graph_lab_vertex_wrapper.html">vertex_type</a> other_vertex = <a class="code" href="als__vertex__program_8hpp.html#a713562b4f44b2663241a3dd6292f0dab" title="Given a vertex and an edge return the other vertex in the edge.">get_other_vertex</a>(edge, vertex);</div>
<div class="line"><a name="l00276"></a><span class="lineno">  276</span>&#160;      <span class="keywordflow">return</span> gather_type(other_vertex.<a class="code" href="structgraphlab_1_1_graph_lab_vertex_wrapper.html#aa15502c3f0ca6fbfe636a25e1e349aa4" title="Returns a constant reference to the data on the vertex.">data</a>().<a class="code" href="structvertex__data.html#a652e9543fe205c866ff39a09fda2ff13" title="how much the latent value has changed">factor</a>, edge.<a class="code" href="structgraphlab_1_1_graph_lab_edge_wrapper.html#a3bfdff77561dc08db04ea7cc3fc4d2c8" title="Returns a constant reference to the data on the edge.">data</a>().<a class="code" href="structedge__data.html#a1fc50f971f9fdbb4c9c90e33bda1c758" title="the observed value for the edge">obs</a>);</div>
<div class="line"><a name="l00277"></a><span class="lineno">  277</span>&#160;    } <span class="keywordflow">else</span> <span class="keywordflow">return</span> gather_type();</div>
<div class="line"><a name="l00278"></a><span class="lineno">  278</span>&#160;  } <span class="comment">// end of gather function</span></div>
<div class="line"><a name="l00279"></a><span class="lineno">  279</span>&#160;</div>
<div class="line"><a name="l00281"></a><span class="lineno"><a class="code" href="classals__vertex__program.html#a38b2ce9db8057202495be03324bba2b5">  281</a></span>&#160;  <span class="keywordtype">void</span> <a class="code" href="classals__vertex__program.html#a38b2ce9db8057202495be03324bba2b5">apply</a>(<a class="code" href="classgraphlab_1_1icontext.html">icontext_type</a>&amp; context, <a class="code" href="structgraphlab_1_1_graph_lab_vertex_wrapper.html">vertex_type</a>&amp; vertex,</div>
<div class="line"><a name="l00282"></a><span class="lineno">  282</span>&#160;             <span class="keyword">const</span> gather_type&amp; sum) {</div>
<div class="line"><a name="l00283"></a><span class="lineno">  283</span>&#160;    <span class="comment">// Get and reset the vertex data</span></div>
<div class="line"><a name="l00284"></a><span class="lineno">  284</span>&#160;    <a class="code" href="structvertex__data.html" title="the vertex data type which contains the latent factor.">vertex_data</a>&amp; vdata = vertex.<a class="code" href="structgraphlab_1_1_graph_lab_vertex_wrapper.html#aa15502c3f0ca6fbfe636a25e1e349aa4" title="Returns a constant reference to the data on the vertex.">data</a>(); </div>
<div class="line"><a name="l00285"></a><span class="lineno">  285</span>&#160;    <span class="comment">// Determine the number of neighbors.  Each vertex has only in or</span></div>
<div class="line"><a name="l00286"></a><span class="lineno">  286</span>&#160;    <span class="comment">// out edges depending on which side of the graph it is located</span></div>
<div class="line"><a name="l00287"></a><span class="lineno">  287</span>&#160;    <span class="keywordflow">if</span>(sum.Xy.size() == 0) { vdata.<a class="code" href="structvertex__data.html#a89b8e42b50a16c7c49a1c76b5b319853" title="The most recent L1 change in the factor value.">residual</a> = 0; ++vdata.<a class="code" href="structvertex__data.html#a0992af23f5489f13f07bc924d68e6379" title="The number of times this vertex has been updated.">nupdates</a>; <span class="keywordflow">return</span>; }</div>
<div class="line"><a name="l00288"></a><span class="lineno">  288</span>&#160;    mat_type XtX = sum.XtX;</div>
<div class="line"><a name="l00289"></a><span class="lineno">  289</span>&#160;    vec_type Xy = sum.Xy;</div>
<div class="line"><a name="l00290"></a><span class="lineno">  290</span>&#160;    <span class="comment">// Add regularization</span></div>
<div class="line"><a name="l00291"></a><span class="lineno">  291</span>&#160;    <span class="keywordflow">for</span>(<span class="keywordtype">int</span> i = 0; i &lt; XtX.rows(); ++i) XtX(i,i) += LAMBDA; <span class="comment">// /nneighbors;</span></div>
<div class="line"><a name="l00292"></a><span class="lineno">  292</span>&#160;    <span class="comment">// Solve the least squares problem using eigen ----------------------------</span></div>
<div class="line"><a name="l00293"></a><span class="lineno">  293</span>&#160;    <span class="keyword">const</span> vec_type old_factor = vdata.<a class="code" href="structvertex__data.html#a652e9543fe205c866ff39a09fda2ff13" title="how much the latent value has changed">factor</a>;</div>
<div class="line"><a name="l00294"></a><span class="lineno">  294</span>&#160;    vdata.<a class="code" href="structvertex__data.html#a652e9543fe205c866ff39a09fda2ff13" title="how much the latent value has changed">factor</a> = XtX.selfadjointView&lt;Eigen::Upper&gt;().ldlt().solve(Xy);</div>
<div class="line"><a name="l00295"></a><span class="lineno">  295</span>&#160;    <span class="comment">// Compute the residual change in the factor factor -----------------------</span></div>
<div class="line"><a name="l00296"></a><span class="lineno">  296</span>&#160;    vdata.<a class="code" href="structvertex__data.html#a89b8e42b50a16c7c49a1c76b5b319853" title="The most recent L1 change in the factor value.">residual</a> = (vdata.<a class="code" href="structvertex__data.html#a652e9543fe205c866ff39a09fda2ff13" title="how much the latent value has changed">factor</a> - old_factor).cwiseAbs().sum() / XtX.rows();</div>
<div class="line"><a name="l00297"></a><span class="lineno">  297</span>&#160;    ++vdata.<a class="code" href="structvertex__data.html#a0992af23f5489f13f07bc924d68e6379" title="The number of times this vertex has been updated.">nupdates</a>;</div>
<div class="line"><a name="l00298"></a><span class="lineno">  298</span>&#160;  } <span class="comment">// end of apply</span></div>
<div class="line"><a name="l00299"></a><span class="lineno">  299</span>&#160;  </div>
<div class="line"><a name="l00301"></a><span class="lineno"><a class="code" href="classals__vertex__program.html#a6854f1ddb0f0bccc3c8e48711320f645">  301</a></span>&#160;  edge_dir_type <a class="code" href="classals__vertex__program.html#a6854f1ddb0f0bccc3c8e48711320f645">scatter_edges</a>(<a class="code" href="classgraphlab_1_1icontext.html">icontext_type</a>&amp; context,</div>
<div class="line"><a name="l00302"></a><span class="lineno">  302</span>&#160;                              <span class="keyword">const</span> <a class="code" href="structgraphlab_1_1_graph_lab_vertex_wrapper.html">vertex_type</a>&amp; vertex)<span class="keyword"> const </span>{ </div>
<div class="line"><a name="l00303"></a><span class="lineno">  303</span>&#160;    <span class="keywordflow">return</span> graphlab::ALL_EDGES; </div>
<div class="line"><a name="l00304"></a><span class="lineno">  304</span>&#160;  }; <span class="comment">// end of scatter edges</span></div>
<div class="line"><a name="l00305"></a><span class="lineno">  305</span>&#160;</div>
<div class="line"><a name="l00307"></a><span class="lineno"><a class="code" href="classals__vertex__program.html#a72eb6fbad2a390df75a023cdf8bbc5fd">  307</a></span>&#160;  <span class="keywordtype">void</span> <a class="code" href="classals__vertex__program.html#a72eb6fbad2a390df75a023cdf8bbc5fd">scatter</a>(<a class="code" href="classgraphlab_1_1icontext.html">icontext_type</a>&amp; context, <span class="keyword">const</span> <a class="code" href="structgraphlab_1_1_graph_lab_vertex_wrapper.html">vertex_type</a>&amp; vertex, </div>
<div class="line"><a name="l00308"></a><span class="lineno">  308</span>&#160;               <a class="code" href="structgraphlab_1_1_graph_lab_edge_wrapper.html">edge_type</a>&amp; <a class="code" href="structedge.html">edge</a>)<span class="keyword"> const </span>{</div>
<div class="line"><a name="l00309"></a><span class="lineno">  309</span>&#160;  <span class="comment">/*  edge_data&amp; edata = edge.data();</span></div>
<div class="line"><a name="l00310"></a><span class="lineno">  310</span>&#160;<span class="comment">    if(edata.role == edge_data::TRAIN) {</span></div>
<div class="line"><a name="l00311"></a><span class="lineno">  311</span>&#160;<span class="comment">      const vertex_type other_vertex = get_other_vertex(edge, vertex);</span></div>
<div class="line"><a name="l00312"></a><span class="lineno">  312</span>&#160;<span class="comment">      const vertex_data&amp; vdata = vertex.data();</span></div>
<div class="line"><a name="l00313"></a><span class="lineno">  313</span>&#160;<span class="comment">      const vertex_data&amp; other_vdata = other_vertex.data();</span></div>
<div class="line"><a name="l00314"></a><span class="lineno">  314</span>&#160;<span class="comment">      const double pred = vdata.factor.dot(other_vdata.factor);</span></div>
<div class="line"><a name="l00315"></a><span class="lineno">  315</span>&#160;<span class="comment">      const float error = std::fabs(edata.obs - pred);</span></div>
<div class="line"><a name="l00316"></a><span class="lineno">  316</span>&#160;<span class="comment">      const double priority = (error * vdata.residual); </span></div>
<div class="line"><a name="l00317"></a><span class="lineno">  317</span>&#160;<span class="comment">      // Reschedule neighbors ------------------------------------------------</span></div>
<div class="line"><a name="l00318"></a><span class="lineno">  318</span>&#160;<span class="comment">      if( priority &gt; TOLERANCE &amp;&amp; other_vdata.nupdates &lt; MAX_UPDATES) </span></div>
<div class="line"><a name="l00319"></a><span class="lineno">  319</span>&#160;<span class="comment">        context.signal(other_vertex, priority);</span></div>
<div class="line"><a name="l00320"></a><span class="lineno">  320</span>&#160;<span class="comment">    }*/</span></div>
<div class="line"><a name="l00321"></a><span class="lineno">  321</span>&#160;  } <span class="comment">// end of scatter function</span></div>
<div class="line"><a name="l00322"></a><span class="lineno">  322</span>&#160;</div>
<div class="line"><a name="l00323"></a><span class="lineno">  323</span>&#160;</div>
<div class="line"><a name="l00327"></a><span class="lineno"><a class="code" href="classals__vertex__program.html#aae00f0768a3086e600178185ae657b2e">  327</a></span>&#160;  <span class="keyword">static</span> <a class="code" href="structgraphlab_1_1empty.html">graphlab::empty</a> <a class="code" href="classals__vertex__program.html#aae00f0768a3086e600178185ae657b2e" title="Signal all vertices on one side of the bipartite graph.">signal_left</a>(<a class="code" href="classgraphlab_1_1icontext.html">icontext_type</a>&amp; context,</div>
<div class="line"><a name="l00328"></a><span class="lineno">  328</span>&#160;                                     <a class="code" href="structgraphlab_1_1_graph_lab_vertex_wrapper.html">vertex_type</a>&amp; vertex) {</div>
<div class="line"><a name="l00329"></a><span class="lineno">  329</span>&#160;    <span class="keywordflow">if</span>(vertex.<a class="code" href="structgraphlab_1_1_graph_lab_vertex_wrapper.html#a3f271cdd29c871a12991826179a17d86" title="Returns the number of out edges of the vertex.">num_out_edges</a>() &gt; 0) context.<a class="code" href="classgraphlab_1_1icontext.html#ab1b5ca81e1c7665a98f4cad04fb0819d" title="Signal a vertex with a particular message.">signal</a>(vertex);</div>
<div class="line"><a name="l00330"></a><span class="lineno">  330</span>&#160;    <span class="keywordflow">return</span> <a class="code" href="structgraphlab_1_1empty.html">graphlab::empty</a>();</div>
<div class="line"><a name="l00331"></a><span class="lineno">  331</span>&#160;  } <span class="comment">// end of signal_left </span></div>
<div class="line"><a name="l00332"></a><span class="lineno">  332</span>&#160;</div>
<div class="line"><a name="l00333"></a><span class="lineno">  333</span>&#160;}; <span class="comment">// end of als vertex program</span></div>
<div class="line"><a name="l00334"></a><span class="lineno">  334</span>&#160;</div>
<div class="line"><a name="l00335"></a><span class="lineno">  335</span>&#160;</div>
<div class="line"><a name="l00336"></a><span class="lineno"><a class="code" href="structerror__aggregator.html">  336</a></span>&#160;<span class="keyword">struct </span><a class="code" href="structerror__aggregator.html">error_aggregator</a> : <span class="keyword">public</span> <a class="code" href="structgraphlab_1_1_i_s___p_o_d___t_y_p_e.html">graphlab::IS_POD_TYPE</a> {</div>
<div class="line"><a name="l00337"></a><span class="lineno">  337</span>&#160;  <span class="keyword">typedef</span> <a class="code" href="classgraphlab_1_1icontext.html">als_vertex_program::icontext_type</a> <a class="code" href="classgraphlab_1_1icontext.html">icontext_type</a>;</div>
<div class="line"><a name="l00338"></a><span class="lineno">  338</span>&#160;  <span class="keyword">typedef</span> <a class="code" href="structgraphlab_1_1_graph_lab_edge_wrapper.html">graph_type::edge_type</a> <a class="code" href="structgraphlab_1_1_graph_lab_edge_wrapper.html">edge_type</a>;</div>
<div class="line"><a name="l00339"></a><span class="lineno">  339</span>&#160;  <span class="keywordtype">double</span> train_error, validation_error;</div>
<div class="line"><a name="l00340"></a><span class="lineno">  340</span>&#160;  <span class="keywordtype">size_t</span> ntrain, nvalidation;</div>
<div class="line"><a name="l00341"></a><span class="lineno">  341</span>&#160;  <a class="code" href="structerror__aggregator.html">error_aggregator</a>() : </div>
<div class="line"><a name="l00342"></a><span class="lineno">  342</span>&#160;    train_error(0), validation_error(0), ntrain(0), nvalidation(0) { }</div>
<div class="line"><a name="l00343"></a><span class="lineno">  343</span>&#160;  <a class="code" href="structerror__aggregator.html">error_aggregator</a>&amp; operator+=(<span class="keyword">const</span> <a class="code" href="structerror__aggregator.html">error_aggregator</a>&amp; other) {</div>
<div class="line"><a name="l00344"></a><span class="lineno">  344</span>&#160;    train_error += other.train_error;</div>
<div class="line"><a name="l00345"></a><span class="lineno">  345</span>&#160;    validation_error += other.validation_error;</div>
<div class="line"><a name="l00346"></a><span class="lineno">  346</span>&#160;    ntrain += other.ntrain;</div>
<div class="line"><a name="l00347"></a><span class="lineno">  347</span>&#160;    nvalidation += other.nvalidation;</div>
<div class="line"><a name="l00348"></a><span class="lineno">  348</span>&#160;    <span class="keywordflow">return</span> *<span class="keyword">this</span>;</div>
<div class="line"><a name="l00349"></a><span class="lineno">  349</span>&#160;  }</div>
<div class="line"><a name="l00350"></a><span class="lineno">  350</span>&#160;  <span class="keyword">static</span> <a class="code" href="structerror__aggregator.html">error_aggregator</a> map(<a class="code" href="classgraphlab_1_1icontext.html">icontext_type</a>&amp; context, <span class="keyword">const</span> <a class="code" href="structgraphlab_1_1_graph_lab_edge_wrapper.html">graph_type::edge_type</a>&amp; <a class="code" href="structedge.html">edge</a>) {</div>
<div class="line"><a name="l00351"></a><span class="lineno">  351</span>&#160;    <a class="code" href="structerror__aggregator.html">error_aggregator</a> agg;</div>
<div class="line"><a name="l00352"></a><span class="lineno">  352</span>&#160;    <span class="keywordflow">if</span>(edge.<a class="code" href="structgraphlab_1_1_graph_lab_edge_wrapper.html#a3bfdff77561dc08db04ea7cc3fc4d2c8" title="Returns a constant reference to the data on the edge.">data</a>().role == edge_data::TRAIN) {</div>
<div class="line"><a name="l00353"></a><span class="lineno">  353</span>&#160;      agg.train_error = <a class="code" href="als__vertex__program_8hpp.html#afb0b8a4655197699932baa2bac0cc465" title="Given an edge compute the error associated with that edge.">extract_l2_error</a>(edge); agg.ntrain = 1;</div>
<div class="line"><a name="l00354"></a><span class="lineno">  354</span>&#160;    } <span class="keywordflow">else</span> <span class="keywordflow">if</span>(edge.<a class="code" href="structgraphlab_1_1_graph_lab_edge_wrapper.html#a3bfdff77561dc08db04ea7cc3fc4d2c8" title="Returns a constant reference to the data on the edge.">data</a>().role == edge_data::VALIDATE) {</div>
<div class="line"><a name="l00355"></a><span class="lineno">  355</span>&#160;      agg.validation_error = <a class="code" href="als__vertex__program_8hpp.html#afb0b8a4655197699932baa2bac0cc465" title="Given an edge compute the error associated with that edge.">extract_l2_error</a>(edge); agg.nvalidation = 1;</div>
<div class="line"><a name="l00356"></a><span class="lineno">  356</span>&#160;    }</div>
<div class="line"><a name="l00357"></a><span class="lineno">  357</span>&#160;    <span class="keywordflow">return</span> agg;</div>
<div class="line"><a name="l00358"></a><span class="lineno">  358</span>&#160;  }</div>
<div class="line"><a name="l00359"></a><span class="lineno">  359</span>&#160;  <span class="keyword">static</span> <span class="keywordtype">void</span> finalize(<a class="code" href="classgraphlab_1_1icontext.html">icontext_type</a>&amp; context, <a class="code" href="structerror__aggregator.html">error_aggregator</a>&amp; agg) {</div>
<div class="line"><a name="l00360"></a><span class="lineno">  360</span>&#160;    ASSERT_GT(agg.ntrain, 0);</div>
<div class="line"><a name="l00361"></a><span class="lineno">  361</span>&#160;    agg.train_error = std::sqrt(agg.train_error / agg.ntrain);</div>
<div class="line"><a name="l00362"></a><span class="lineno">  362</span>&#160;    context.<a class="code" href="classgraphlab_1_1icontext.html#a7f827dd93aba5809b69cf659554f8869" title="Returns a standard output object (like cout) which only prints once even when running distributed...">cout</a>() &lt;&lt; context.<a class="code" href="classgraphlab_1_1icontext.html#a863010fd33f3721162d253af3583f8bb" title="Get the elapsed time in seconds since start was called.">elapsed_seconds</a>() &lt;&lt; <span class="stringliteral">&quot;\t&quot;</span> &lt;&lt; agg.train_error;</div>
<div class="line"><a name="l00363"></a><span class="lineno">  363</span>&#160;    <span class="keywordflow">if</span>(agg.nvalidation &gt; 0) {</div>
<div class="line"><a name="l00364"></a><span class="lineno">  364</span>&#160;      <span class="keyword">const</span> <span class="keywordtype">double</span> validation_error = </div>
<div class="line"><a name="l00365"></a><span class="lineno">  365</span>&#160;        std::sqrt(agg.validation_error / agg.nvalidation);</div>
<div class="line"><a name="l00366"></a><span class="lineno">  366</span>&#160;      context.<a class="code" href="classgraphlab_1_1icontext.html#a7f827dd93aba5809b69cf659554f8869" title="Returns a standard output object (like cout) which only prints once even when running distributed...">cout</a>() &lt;&lt; <span class="stringliteral">&quot;\t&quot;</span> &lt;&lt; validation_error; </div>
<div class="line"><a name="l00367"></a><span class="lineno">  367</span>&#160;    }</div>
<div class="line"><a name="l00368"></a><span class="lineno">  368</span>&#160;    context.<a class="code" href="classgraphlab_1_1icontext.html#a7f827dd93aba5809b69cf659554f8869" title="Returns a standard output object (like cout) which only prints once even when running distributed...">cout</a>() &lt;&lt; std::endl;</div>
<div class="line"><a name="l00369"></a><span class="lineno">  369</span>&#160;  }</div>
<div class="line"><a name="l00370"></a><span class="lineno">  370</span>&#160;}; <span class="comment">// end of error aggregator</span></div>
<div class="line"><a name="l00371"></a><span class="lineno">  371</span>&#160;</div>
<div class="line"><a name="l00372"></a><span class="lineno">  372</span>&#160;</div>
<div class="line"><a name="l00373"></a><span class="lineno"><a class="code" href="structprediction__saver.html">  373</a></span>&#160;<span class="keyword">struct </span><a class="code" href="structprediction__saver.html">prediction_saver</a> {</div>
<div class="line"><a name="l00374"></a><span class="lineno">  374</span>&#160;  <span class="keyword">typedef</span> <a class="code" href="structgraphlab_1_1_graph_lab_vertex_wrapper.html">graph_type::vertex_type</a> <a class="code" href="structgraphlab_1_1_graph_lab_vertex_wrapper.html">vertex_type</a>;</div>
<div class="line"><a name="l00375"></a><span class="lineno">  375</span>&#160;  <span class="keyword">typedef</span> <a class="code" href="structgraphlab_1_1_graph_lab_edge_wrapper.html">graph_type::edge_type</a>   <a class="code" href="structgraphlab_1_1_graph_lab_edge_wrapper.html">edge_type</a>;</div>
<div class="line"><a name="l00376"></a><span class="lineno">  376</span>&#160;  std::string save_vertex(<span class="keyword">const</span> <a class="code" href="structgraphlab_1_1_graph_lab_vertex_wrapper.html">vertex_type</a>&amp; vertex)<span class="keyword"> const </span>{</div>
<div class="line"><a name="l00377"></a><span class="lineno">  377</span>&#160;    <span class="keywordflow">return</span> <span class="stringliteral">&quot;&quot;</span>; <span class="comment">//nop</span></div>
<div class="line"><a name="l00378"></a><span class="lineno">  378</span>&#160;  }</div>
<div class="line"><a name="l00379"></a><span class="lineno">  379</span>&#160;  std::string save_edge(<span class="keyword">const</span> <a class="code" href="structgraphlab_1_1_graph_lab_edge_wrapper.html">edge_type</a>&amp; <a class="code" href="structedge.html">edge</a>)<span class="keyword"> const </span>{</div>
<div class="line"><a name="l00380"></a><span class="lineno">  380</span>&#160;    std::stringstream strm;</div>
<div class="line"><a name="l00381"></a><span class="lineno">  381</span>&#160;    <span class="keyword">const</span> <span class="keywordtype">double</span> prediction = </div>
<div class="line"><a name="l00382"></a><span class="lineno">  382</span>&#160;      edge.<a class="code" href="structgraphlab_1_1_graph_lab_edge_wrapper.html#a1176dc7f68117e758dad6c65dd7c7358" title="Returns the source vertex of the edge. This function returns a vertex_object by value and as a conseq...">source</a>().<a class="code" href="structgraphlab_1_1_graph_lab_vertex_wrapper.html#aa15502c3f0ca6fbfe636a25e1e349aa4" title="Returns a constant reference to the data on the vertex.">data</a>().factor.dot(edge.<a class="code" href="structgraphlab_1_1_graph_lab_edge_wrapper.html#a6c4d5eaded1d40e10775707ff7189dc7" title="Returns the target vertex of the edge.">target</a>().<a class="code" href="structgraphlab_1_1_graph_lab_vertex_wrapper.html#aa15502c3f0ca6fbfe636a25e1e349aa4" title="Returns a constant reference to the data on the vertex.">data</a>().factor);</div>
<div class="line"><a name="l00383"></a><span class="lineno">  383</span>&#160;    strm &lt;&lt; edge.<a class="code" href="structgraphlab_1_1_graph_lab_edge_wrapper.html#a1176dc7f68117e758dad6c65dd7c7358" title="Returns the source vertex of the edge. This function returns a vertex_object by value and as a conseq...">source</a>().<a class="code" href="structgraphlab_1_1_graph_lab_vertex_wrapper.html#abcc164070e228a8133c627703c1917f0" title="Returns the vertex ID of the vertex.">id</a>() &lt;&lt; <span class="charliteral">&#39;\t&#39;</span> </div>
<div class="line"><a name="l00384"></a><span class="lineno">  384</span>&#160;         &lt;&lt; edge.<a class="code" href="structgraphlab_1_1_graph_lab_edge_wrapper.html#a6c4d5eaded1d40e10775707ff7189dc7" title="Returns the target vertex of the edge.">target</a>().<a class="code" href="structgraphlab_1_1_graph_lab_vertex_wrapper.html#abcc164070e228a8133c627703c1917f0" title="Returns the vertex ID of the vertex.">id</a>() &lt;&lt; <span class="charliteral">&#39;\t&#39;</span></div>
<div class="line"><a name="l00385"></a><span class="lineno">  385</span>&#160;         &lt;&lt; prediction &lt;&lt; <span class="charliteral">&#39;\n&#39;</span>;</div>
<div class="line"><a name="l00386"></a><span class="lineno">  386</span>&#160;    <span class="keywordflow">return</span> strm.str();</div>
<div class="line"><a name="l00387"></a><span class="lineno">  387</span>&#160;  }</div>
<div class="line"><a name="l00388"></a><span class="lineno">  388</span>&#160;}; <span class="comment">// end of prediction_saver</span></div>
<div class="line"><a name="l00389"></a><span class="lineno">  389</span>&#160;</div>
<div class="line"><a name="l00390"></a><span class="lineno">  390</span>&#160;</div>
<div class="line"><a name="l00391"></a><span class="lineno">  391</span>&#160;</div>
<div class="line"><a name="l00392"></a><span class="lineno">  392</span>&#160;</div>
<div class="line"><a name="l00393"></a><span class="lineno">  393</span>&#160;<span class="preprocessor">#endif</span></div>
</div><!-- fragment --></div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated on Thu Jul 5 2012 00:11:17 for GraphChi by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.1.1
</small></address>
</body>
</html>
